Skip to content

[azure-ai-ml] Forward list_view_type for registry model-version listing in MLClient.models.list#47179

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-registry-model-list-view-type
Draft

[azure-ai-ml] Forward list_view_type for registry model-version listing in MLClient.models.list#47179
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-registry-model-list-view-type

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 27, 2026

MLClient.models.list(name=..., list_view_type=...) was dropping list_view_type when scoped to a registry, so registry model filtering (ActiveOnly/ArchivedOnly/All) did not work even though the 2021-10 dataplane client supports listViewType. This PR wires the missing argument through the operations layer without changing API version or method signatures.

  • Operations fix (registry name branch)

    • Updated ModelOperations.list in azure/ai/ml/operations/_model_operations.py to pass list_view_type to self._model_versions_operation.list(...) when registry_name is set.
    • Preserves current behavior of not forwarding stage on registry-scoped version listing.
  • Unit test coverage (workspace + registry parity)

    • Extended tests/model/unittests/test_model_operations.py with a focused test asserting:
      • registry call forwards name, registry_name, list_view_type
      • workspace call forwards name, workspace_name, list_view_type, stage
      • registry call does not pass stage
  • Changelog

    • Added a Bugs Fixed entry under the current unreleased section in sdk/ml/azure-ai-ml/CHANGELOG.md describing the registry list_view_type fix.
# before (registry scoped): list_view_type was omitted
self._model_versions_operation.list(
    name=name,
    registry_name=self._registry_name,
    cls=lambda objs: [Model._from_rest_object(obj) for obj in objs],
    **self._scope_kwargs,
)

# after
self._model_versions_operation.list(
    name=name,
    registry_name=self._registry_name,
    cls=lambda objs: [Model._from_rest_object(obj) for obj in objs],
    list_view_type=list_view_type,
    **self._scope_kwargs,
)
Original prompt

Summary

In azure-ai-ml, MLClient.models.list(name=..., list_view_type=...) silently ignores the list_view_type argument when the client is scoped to a registry (i.e. MLClient(..., registry_name=...)). As a result, customers cannot filter registry models by ActiveOnly / ArchivedOnly / All.

The underlying generated REST client for the 2021-10-01-dataplanepreview API version does accept and serialize list_view_type into the ?listViewType= query parameter (see build_list_request in sdk/ml/azure-ai-ml/azure/ai/ml/_restclient/v2021_10_01_dataplanepreview/operations/_model_versions_operations.py). The bug is purely in the operations layer not forwarding the kwarg.

No API version upgrade is required to fix this customer-visible bug.

Root cause

File: sdk/ml/azure-ai-ml/azure/ai/ml/operations/_model_operations.py

In the list method, the workspace branch forwards list_view_type but the registry branch does not:

@monitor_with_activity(ops_logger, "Model.List", ActivityType.PUBLICAPI)
def list(
    self,
    name: Optional[str] = None,
    stage: Optional[str] = None,
    *,
    list_view_type: ListViewType = ListViewType.ACTIVE_ONLY,
) -> Iterable[Model]:
    ...
    if name:
        return cast(
            Iterable[Model],
            (
                self._model_versions_operation.list(
                    name=name,
                    registry_name=self._registry_name,
                    cls=lambda objs: [Model._from_rest_object(obj) for obj in objs],
                    **self._scope_kwargs,
                    # <-- list_view_type is missing here
                )
                if self._registry_name
                else self._model_versions_operation.list(
                    name=name,
                    workspace_name=self._workspace_name,
                    cls=lambda objs: [Model._from_rest_object(obj) for obj in objs],
                    list_view_type=list_view_type,
                    stage=stage,
                    **self._scope_kwargs,
                )
            ),
        )

The container-level branch right below already forwards list_view_type correctly in both arms; only the name-based versions branch is broken.

Required change

In sdk/ml/azure-ai-ml/azure/ai/ml/operations/_model_operations.py, inside ModelOperations.list, pass list_view_type=list_view_type to the registry-branch call:

self._model_versions_operation.list(
    name=name,
    registry_name=self._registry_name,
    cls=lambda objs: [Model._from_rest_object(obj) for obj in objs],
    list_view_type=list_view_type,
    **self._scope_kwargs,
)

Notes / constraints:

  • Do not forward stage on the registry branch — the 2021-10 dataplane model_versions.list signature does not accept it. Current behavior (silently ignored on registries) is preserved.
  • If an async variant of _model_operations.py exists under azure/ai/ml/operations/ or azure/ai/ml/_operations/, apply the same fix there for parity.
  • Do not change the public signature of ModelOperations.list.

Tests

Add (or extend) a unit test under sdk/ml/azure-ai-ml/tests/model/ that:

  1. Constructs a ModelOperations instance with registry_name set, using a mock service_client whose model_versions.list is a MagicMock.
  2. Calls ops.list(name="my-model", list_view_type=ListViewType.ARCHIVED_ONLY) and iterates it.
  3. Asserts that service_client.model_versions.list was called with list_view_type=ListViewType.ARCHIVED_ONLY (and registry_name=..., name="my-model").
  4. Also asserts the existing workspace-branch behavior still forwards list_view_type and stage.

Look at neighboring tests (e.g. existing model ops tests) for the established mocking pattern in this package.

Changelog

Add an entry under the next unreleased version in sdk/ml/azure-ai-ml/CHANGELOG.md under Bugs Fixed:

  • Fixed MLClient.models.list ignoring the list_view_type filter when the client is scoped to a registry. Archived/active filtering on registry models now works as documented.

Validation

From sdk/ml/azure-ai-ml:

  • pip install -e .
  • Run the package's existing pytest suite for model ops to ensure no regressions.
  • Optionally, run azpysdk pylint . and azpysdk mypy . and ensure no new warnings/errors are introduced by the change.

Out of scope

  • Upgrading the registry data-plane API version beyond 2021-10-01-dataplanepreview. (The newer 2023-04-01-preview / 2025-01-01-preview RegistryModelVersionsOperations.list also accept list_view_type, but switching API versions is a larger change and is not required to unblock the reported customer scenario.)
  • Any changes to _model_container_operation.list(...) — it already forwards list_view_type correctly.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: ListViewType Not Filtering Models in SDK V2

We are unable to fetch models bas...

This pull request was created from Copilot chat.

Co-authored-by: lavakumarrepala <221403938+lavakumarrepala@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix registry model listing to respect list_view_type argument [azure-ai-ml] Forward list_view_type for registry model-version listing in MLClient.models.list May 27, 2026
Copilot AI requested a review from lavakumarrepala May 27, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants